/*
 * Copyright (c) 2017 22420103@QQ.COM 版权所有
 */
package com.lehe.common;

import java.lang.reflect.Field;

/**
 * 业务消息定义<br>
 *
 * @author 王丹
 * @since 2017-02-22
 */
public class MessageEnumDto {

    /** 验证类错误码 */
    public static final MessageEnumDto SUCCESS = new MessageEnumDto("0", "成功");
    public static final MessageEnumDto FAIL = new MessageEnumDto("1", "失败");

    public static final MessageEnumDto I1000 = new MessageEnumDto("801000", "业务执行方法不存在");
    public static final MessageEnumDto I1001 = new MessageEnumDto("801001", "您已经签过");
    public static final MessageEnumDto I1002 = new MessageEnumDto("801002", "还未开始签到");

    public static final MessageEnumDto E9000 = new MessageEnumDto("909000", "数据实体已经被修改");
    public static final MessageEnumDto E9999 = new MessageEnumDto("909999", "系统异常");
    

    protected String messageCode;
    protected String messageValue;

    public MessageEnumDto(String code, String value) {

        this.messageCode = code;
        this.messageValue = value;
    }

    public static MessageEnumDto valueOf(String code) {

        try {
            Class<MessageEnumDto> c = MessageEnumDto.class;
            Field[] fs = c.getFields();
            for (Field f : fs) {
                if (f.getName().equals(code)) {
                    return (MessageEnumDto) f.get(new MessageEnumDto("", ""));
                }
            }
        } catch (Exception e) {
        }
        return null;
    }

    public String name() {

        return messageCode;
    }

    public void setMessageCode(String messageCode) {
        this.messageCode = messageCode;
    }

    public void setMessageValue(String messageValue) {
        this.messageValue = messageValue;
    }

    public String getMessageCode() {

        return messageCode;
    }

    public String getMessageValue() {

        return messageValue;
    }

    public boolean isSuccess() {

        boolean ret = false;
        if (MessageEnumDto.SUCCESS.getMessageCode().equals(this.messageCode)) {
            ret = true;
        }
        return ret;
    }

    @Override
    public String toString() {

        return this.messageCode;
    }

    public static boolean isSuccess(String code) {

        boolean ret = false;
        if (MessageEnumDto.SUCCESS.getMessageCode().equals(code)) {
            ret = true;
        }
        return ret;
    }
}
